package com.neo.mysql.controller;

import java.util.HashMap;
import java.util.Map;

import com.neo.common.BaseResult;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(path = "/api/mysql")
@Slf4j
public class MysqlAPIController {
    // spring.datasource.url=jdbc:mysql:// localhost:3306/test
    // spring.datasource.username=root
    // spring.datasource.password=aaaabbbb
    // spring.datasource.driver-class-name=com.mysql.jdbc.Driver

    @Value("${spring.datasource.url}")
    private String db;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;

    // /list
    @GetMapping("/info")
    public BaseResult getDBInfo() {
        // Map<String, String> map = new HashMap<String,String>(); //数据采用的哈希表结构
        // //给map中添加元素
        // map.put("星期一", "Monday");
        // map.put("星期日", "Sunday");
        // System.out.println(map); // {星期日=Sunday, 星期一=Monday}

        log.info("#########  info  #########");
        log.debug("#########  debug  #########");
        log.error("#########  error  #########");

        Map<String, String> info = new HashMap<String, String>();
        // Map info = new Map();
        info.put("db", db);
        info.put("username", username);
        info.put("password", password);

        return BaseResult.successWithData(info);

        // return BaseResult.failWithCodeAndMsg(200, "上传失败");
    }

    // mysql crud

    // // 增
    // router.post('/',

    // async (req, res) => {
    // const model = await req.Model.create(req.body)
    // res.send(model)
    // });
    // // 查 populate - 查看父级
    // router.get('/', async (req, res) => {
    // const queryOptions = {};
    // if (req.Model.modelName === 'Category') {
    // queryOptions.populate = 'parent'
    // }
    // const items = await req.Model.find().setOptions(queryOptions).limit(10);
    // res.send(items);
    // });
    // // 根据ID查
    // router.get('/:id', async (req, res) => {
    // const model = await req.Model.findById(req.params.id);
    // res.send(model);
    // });
    // // 改
    // router.put('/:id', async (req, res) => {
    // const model = await req.Model.findByIdAndUpdate(req.params.id, req.body);
    // res.send(model);
    // });
    // // 删
    // router.delete('/:id', async (req, res) => {

}
